'use strict';
/*
*paging方法用于将常规sql语句进行分页和排序的扩展。

*/
module.exports = function (sql, pagingParam) {
    let [sort, dir, start, limit, paging] = [pagingParam.sort, pagingParam.dir, pagingParam.start, pagingParam.limit, false];
    //满足排序的相关参数则进行排序的sql语句添加
    if (sort && dir) {
        sql += ` ORDER BY ${sort} ${dir}`;
    }
    if (start && limit) {
        //满足分页的相关参数则进行分页的sql语句添加，并标记此sql语句已经被分页
        sql = `${sql.replace(/SELECT/i, 'SELECT SQL_CALC_FOUND_ROWS')} LIMIT ${start} ,${limit};SELECT FOUND_ROWS() AS count;`;
        paging = true;
    }
    return {sql: sql, paging: paging};
};